// 专门用来提交内容的
import React, { Component } from 'react';

import { connect } from 'react-redux';
import {ADD_TODO} from './store/types'
class Header extends Component {
  inpRef = React.createRef()
  render() {
    return (
      <div className='header'>

          <input type="text" ref={this.inpRef} />
          <button onClick={()=>{
            // console.log(this.inpRef.current.value);
            // 添加时需要的对象
            const obj = {
              title: this.inpRef.current.value,
              is: false,
              id: String(Math.random())
            }
            // 将 obj 提交到全局中
            this.props.addItem(obj)

            // 将输入框清空
            this.inpRef.current.value = ''
          }}>提交</button>
      </div>
    );
  }
}

export default connect(null,(dispatch)=>{
  return {
    addItem(obj){
      dispatch({type: ADD_TODO, payload: obj})
    }
  }
})(Header);
